package com.wanhe.vip.module.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wanhe.vip.R;
import com.wanhe.vip.api.bean.VipCard;

import java.util.ArrayList;

/**
 * 会员卡列表Adapter
 * Created by XieZaiWei on 2017/3/9.
 */

public class VipCardListAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private ArrayList<VipCard> mArrCard;


    public VipCardListAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    public void setData(ArrayList<VipCard> arrCard) {
        mArrCard = arrCard;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mArrCard.size();
    }

    @Override
    public VipCard getItem(int position) {
        return mArrCard.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.vip_card_item, null);
            viewHolder.tv_cardNumber = (TextView) convertView.findViewById(R.id.tv_cardNumber);
            viewHolder.tv_birthday = (TextView) convertView.findViewById(R.id.tv_birthday);
            viewHolder.tv_sex = (TextView) convertView.findViewById(R.id.tv_sex);
            viewHolder.tv_gradeName = (TextView) convertView.findViewById(R.id.tv_gradeName);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_mobile = (TextView) convertView.findViewById(R.id.tv_mobile);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_cardNumber.setText("卡号："+mArrCard.get(position).getCardNumber());
        viewHolder.tv_birthday.setText("生日："+mArrCard.get(position).getBirthday());
        viewHolder.tv_sex.setText("性别："+mArrCard.get(position).getSex());
        viewHolder.tv_gradeName.setText("等级："+mArrCard.get(position).getGradeName());
        viewHolder.tv_name.setText("姓名："+mArrCard.get(position).getName());
        viewHolder.tv_mobile.setText("手机："+mArrCard.get(position).getMobile());

        return convertView;
    }

    private static class ViewHolder {
        public TextView tv_cardNumber;
        public TextView tv_birthday;
        public TextView tv_sex;
        public TextView tv_gradeName;
        public TextView tv_name;
        public TextView tv_mobile;
    }
}
